home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 3488 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  69 lines

  1. Path: ix.netcom.com!netnews
  2. From: jkarcher@ix.netcom.com(John J. Karcher )
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Referances troubble
  5. Date: 21 Feb 1996 00:35:12 GMT
  6. Organization: Netcom
  7. Message-ID: <4gdpc0$9to@reader2.ix.netcom.com>
  8. References: <1266.6624T117T1455@himolde.no>
  9. NNTP-Posting-Host: ix-vf4-02.ix.netcom.com
  10. X-NETCOM-Date: Tue Feb 20  4:35:12 PM PST 1996
  11.  
  12. In <1266.6624T117T1455@himolde.no> Espen.Berntsen@himolde.no (Nameless) writes: 
  13. >
  14. >Ok, I have aslight problem with references. The problem is that I have to pass a
  15. >few pointers to a subroutine, where things are done to them, and then they are
  16. >passed back. Now, what I hoped would work was something like this
  17. >
  18.  
  19. ..
  20.  
  21. >void Tester(void &Testering)
  22. >{
  23. >    printf("%i\n",Testering);
  24. >    Testering = AllocMem(100, MEMF_CHIP|MEMF_CLEAR);
  25. >    printf("%i\n",Testering);
  26. >}
  27. >
  28. >void main(void)
  29. >{
  30. >    void *Test;
  31. >
  32. >    printf("%i\n",Test);
  33. >    Tester(Test);
  34. >
  35. >    printf("%i\n",Test);
  36. >//   FreeMem(Test, 100);
  37. >}
  38.  
  39.  
  40. There are two problems here (as far as I can tell).  Try:
  41.  
  42. void Tester(void **Testering)       // (void &Testering) will not yield
  43.                                     // the desired result
  44. {
  45.     printf("%i\n",*Testering);
  46.     *Testering = AllocMem(100, MEMF_CHIP|MEMF_CLEAR);
  47.     printf("%i\n",*Testering);
  48. }
  49.  
  50. void main(void)
  51. {
  52.     void *Test;
  53.  
  54.     printf("%i\n",Test);
  55.     Tester(&Test);
  56.  
  57.     printf("%i\n",Test);
  58. //   FreeMem(Test, 100);
  59. }
  60.  
  61. The idea here is to pass a pointer to the pointer.  If you just pass
  62. the pointer, modifying it will have no effect on the original.  By
  63. passing a pointer to your original pointer, modifying *Testering will
  64. modify the original pointer.
  65.  
  66.     - John J. Karcher
  67.  
  68.  
  69.